package algorithm;

import com.alibaba.fastjson.JSON;

import java.util.LinkedHashMap;
import java.util.Map;

public class Test15LRU<K,V> extends LinkedHashMap<K,V>  {
    static final int cacheSize=6;
    public Test15LRU(int initialCapacity, float loadFactor, boolean accessOrder) {
        super(initialCapacity, loadFactor, accessOrder);

    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        if(size()>6){
            return true;
        }else{
            return false;
        }
    }

    public static void main(String[] args) {
        Test15LRU<Integer, String> lru = new Test15LRU<Integer, String>(16, 0.75f, true);
        for(int i=0;i<10;i++){
            if(i>4){
                lru.get(1);
                lru.get(2);
            }
            lru.put(i,i+"a");
        }

        System.out.println(lru.size());
        System.out.println(JSON.toJSONString(lru));

    }

}
